﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for Image
/// </summary>
public class ImageData
{
    private string tablename = "tbl_images";
    private string[] file = {"id","url","link","alt","width","height","author" };
	public ImageData()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool add(ImageEntities item)
    {
        bool flat = false;
        string[] values = {item._url,item._link,item._alt,item._width,item._height,item._author };
        string query = SQL.Insert(tablename, file, values);
        if (Database.getExec(query) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public bool edit(ImageEntities item)
    {
        bool flat = false;
        string[] values = { item._id.ToString(),item._url, item._link, item._alt, item._width, item._height, item._author };
        string query = SQL.Update(tablename, file, values);
        if (Database.getExec(query) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public bool delete(int id)
    {
        bool flat = false;
        string query = "delete from tbl_images where id = '" + id.ToString() + "'";
        if (Database.getExec(query) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public DataTable getImage(int id)
    {
        if (id > 0)
        {
            string query = "SELECT * FROM tbl_images where id='" + id.ToString() + "'";
            return Database.getTable(query);
        }
        else
        {
            string query = "SELECT * FROM tbl_images order by tbl_images.id desc ";
            return Database.getTable(query);
        }
    }

    public DataTable getPanel_Image(int panel_id)
    {
        DataTable dt = new DataTable();
        if (panel_id > 0)
        {
            string query = "SELECT tbl_images.id,url,link,alt,width,height,author FROM tbl_images,tbl_panellist  "+
                           "WHERE panel_id ='" + panel_id.ToString() + "' order by tbl_images.id desc ";
            dt = Database.getTable(query);
        }
        return dt;
    }
}
